package com.android.delivery.activity

import android.content.Context
import android.content.Intent
import android.widget.FrameLayout
import androidx.recyclerview.widget.RecyclerView
import com.android.delivery.R
import com.android.delivery.adapter.CapitalAdapter
import com.android.delivery.api.ApiService
import com.android.delivery.base.BaseListActivity
import com.android.delivery.callback.DialogCallback
import com.android.delivery.callback.LzyResponse
import com.android.delivery.entity.AccountBill
import com.android.delivery.util.DensityUtil
import com.lzy.okgo.model.Response

/**
 * @author: mqwang
 * @create: 2/10/21 12:07 AM
 * @Description: 资金明细
 */
class CapitalListActivity : BaseListActivity<AccountBill>() {

    private val addrAdapter: CapitalAdapter by lazy {
        CapitalAdapter()
    }

    companion object {
        fun self(context: Context) {
            val intent = Intent(context, CapitalListActivity::class.java)
            context.startActivity(intent)
        }
    }

    override fun bindRecyclerView(recLv: RecyclerView?) {
        recLv!!.adapter = addrAdapter
        setMainTitle("资金明细")

        val margin = DensityUtil.dp2px(12f)
        (recLv.layoutParams as FrameLayout.LayoutParams).setMargins(margin, margin, margin, margin)
        recLv.setBackgroundResource(R.drawable.bg_common)
    }

    override fun loadData(page: Int, pageCount: Int) {
        ApiService.user_account_list(this, page, object : DialogCallback<LzyResponse<AccountBill>>() {
            override fun onSuccess(response: Response<LzyResponse<AccountBill>>?) {
                val records = response!!.body().data.records
                onGetDataSuc(records)
            }
        })
    }

    override fun getData(): MutableList<AccountBill> {
        return addrAdapter.data
    }

    override fun bindData(isRefresh: Boolean, list: MutableList<AccountBill>?) {
        when (isRefresh) {
            true -> {
                addrAdapter.setNewData(list)
            }
            false -> {
                addrAdapter.addData(list!!)
            }
        }
    }
}